import {defineConfig} from 'vite'
import react from '@vitejs/plugin-react'
import {VitePWA} from "vite-plugin-pwa";
import {join} from 'path';
import pages from 'vite-plugin-pages'

// https://vite.dev/config/
export default defineConfig({
    plugins: [
        react(),
        VitePWA({
            registerType: 'autoUpdate',
            devOptions: {
                // 生成清单文件
                enabled: true
            },
            manifest: {
                name: "vue-quick-start",
                theme_color: '#ff5e3a',
                icons: [
                    {
                        src: 'assets/logo.png',
                        size: '192x192',
                        type: 'image/png'
                    }
                ]
            },
            workbox: {
                globPatterns: ['**/*.{js,css,html,png,jpg}']
            }
        }),
        /*pages({
            // 自定义配置
            // dir: 'src/pages',          // 路由组件目录
            extensions: ['jsx', 'tsx'], // 支持文件后缀
            // exclude: ['components'],  // 排除组件目录
            base: process.env.VITE_APP_BASE_URL
        }),*/
        pages({
            // 注册多个目录, 有不同的路由前缀
            dirs: [
                // basic
                { dir: 'src/pages', baseRoute: '' },
                // with custom file pattern
                { dir: 'src/admin/', baseRoute: 'admin'},
            ],
        }),
    ],
    // optimizeDeps: {
    //     include: ['react', 'react-dom'],
    // },
    resolve: {
        alias: {
            '@':
                join(__dirname, 'src'),
        }
    },
})
